package cloud.zhixinglu.www.spring.boot.email.factory;

import cloud.zhixinglu.www.spring.boot.email.enums.MailContentTypeEnum;
import java.util.HashMap;
import java.util.Map;


/**
 * 邮件类型工厂类
 *
 * @author weixin
 * @date 2023/8/3 12:10
 */
public class MailFactory {

    private MailFactory() {
    }

    private static final class InnerMailFactory {
        private static final MailFactory MAIL_FACTORY = new MailFactory();
    }

    /**
     * 对应邮件类型类集合
     */
    private static final Map<String, String> MAPS = new HashMap<>();

    static {
        MAPS.put(MailContentTypeEnum.TEXT.value(), getStrategyClassName("simple"));
        MAPS.put(MailContentTypeEnum.HTML.value(), getStrategyClassName("html"));
        MAPS.put(MailContentTypeEnum.TEMPLATE.value(), getStrategyClassName("template"));
    }

    public static MailFactory getInstance() {
        return InnerMailFactory.MAIL_FACTORY;
    }

    public String get(String type) {
        return MAPS.get(type);
    }

    /**
     * 获取策略类名
     *
     * @param classNamePrefix {@link String} 类名前缀
     * @return String
     */
    private static String getStrategyClassName(String classNamePrefix) {
        return classNamePrefix + "MailStrategy";
    }

}
